package cn.edu.neusoft.wuguangsheng.market.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.market.R;
import cn.edu.neusoft.wuguangsheng.market.adapter.showOrderAdapter;
import cn.edu.neusoft.wuguangsheng.market.bean.OrderFoodResut;
import cn.edu.neusoft.wuguangsheng.market.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.market.model.OrderModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class OrderFragment extends BaseFragment {
    RecyclerView recyclercart;
    private List<OrderFoodResut> items;
    Boolean up=false;
    @Override
    void initView() {
        recyclercart=(RecyclerView) view.findViewById(R.id.recycleorder);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclercart.setLayoutManager(linearLayoutManager);
        String uid=getid();
        OrderModel orderModel=new OrderModel();
        orderModel.showOrder(uid,listListener);

    }

    @Override
    void initEvent() {

    }

    @Override
    void initDate() {

    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        setLayout_file(R.layout.fragment_order);
        //Log.v(TAG,"onCreateView");
        return super.onCreateView(inflater,container,savedInstanceState);
    }
    @Override
    public int getLayout_file() {
        return super.getLayout_file();
    }

    @Override
    public void setLayout_file(int layout_file) {
        super.setLayout_file(layout_file);
    }
    ListListener<OrderFoodResut> listListener=new ListListener<OrderFoodResut>() {
        @Override
        public void onResponse(List<OrderFoodResut> list) {
            items=list;

            showOrderAdapter showorderAdapter=new showOrderAdapter(getContext(),items,R.layout.itemorder);
            recyclercart.setAdapter(showorderAdapter);
            recyclercart.setItemAnimator(new DefaultItemAnimator());
        }

        @Override
        public void onFail(String msg) {

        }
    };


    @Override
    public void onPause() {
        super.onPause();
        up=true;
    }

    @Override
    public void onResume() {
        super.onResume();
        if(up){
            initView();
            up=false;
        }
    }
}
